package com.source.multithread.singleton;

/**
 * @Author wengqy
 * @Date 2020/12/25
 */
public class SingleTon {
    private static boolean  flag =false;
    private SingleTon(){
        synchronized(SingleTon.class){
            if(flag==false){
                flag = true;
            }else {
                throw new RuntimeException("不允许破坏单利模式");
            }
          /*  if(singleTon!=null){
                System.out.println(Thread.currentThread().getName()+"不为空");
                throw new RuntimeException("不允许破坏单利模式");
            }*/
        }

    }

    private static  SingleTon  singleTon;

    public  static SingleTon getSingleTon(){

        if(singleTon==null){
            synchronized(SingleTon.class){
                if(singleTon==null){
                    singleTon = new SingleTon();
                }
            }
        }
        return singleTon;
    }
}
